local ClientOHOH = _G.ClientOHOH;
local M = ClientOHOH.class.new(script, ClientOHOH.files.OHOHOLYBUIBase());
local BigNumberHelper = ClientOHOH.load.BigNumberHelper();
function InitInsts(ui)
	ui.insts = {};
    ui.insts.Damage ={
		num="ctrl.Damage.lv",
		btn="ctrl.Damage.btn",
	} 

    ui.insts.Hp ={
		num="ctrl.Defense.lv",
		btn="ctrl.Defense.btn",
	} 
	
    ui.insts.Speed ={
		num="ctrl.Speed.lv",
		btn="ctrl.Speed.btn",
	} 
	
    ui.insts.Luck ={
		num="ctrl.Luck.lv",
		btn="ctrl.Luck.btn",
	} 

    ui.insts.HadPoints="ctrl.hadPoints"
    ui.insts.CostPoints="ctrl.costPoints"
    ui.insts.Refund={
        icon="ctrl.Refund.icon",
        cost="ctrl.Refund.cost",
        btn="ctrl.Refund.btn",
    }

    ui.insts.Close="ctrl.close"

end

function M.new(...)
	return M(...);
end;

function M.ctor(self)
	InitInsts(self)
    M.super.ctor(self, ClientOHOH:GetPath_Loop("ReplicatedStorage.Resource.UI.PointGui"));
    self.insts.CostPoints.Text =1
end;

function M.InitData(self,data)

    self.Model=data
    self.Model.UpdEvent:Connect(function()
        self:Upd(self.Model)
    end)

    ClientOHOH.load.CallBackManager():AddRbxConnect(self,self.insts.Close.Activated, function()
        self:Hide()
    end);

    ClientOHOH.load.CallBackManager():AddRbxConnect(self,self.insts.Refund.btn.Activated, function()
        self.Model.RefundEvent:Action()
    end);

    ClientOHOH.load.CallBackManager():AddRbxConnect(self,self.insts.Luck.btn.Activated, function()
        self.Model.UsePointEvent:Action("lucky",self:GetUsePoints())
    end);
    
    ClientOHOH.load.CallBackManager():AddRbxConnect(self,self.insts.Hp.btn.Activated, function()
        self.Model.UsePointEvent:Action("hp",self:GetUsePoints())
    end);
    
    ClientOHOH.load.CallBackManager():AddRbxConnect(self,self.insts.Damage.btn.Activated, function()
        self.Model.UsePointEvent:Action("damge",self:GetUsePoints())
    end);
    
    ClientOHOH.load.CallBackManager():AddRbxConnect(self,self.insts.Speed.btn.Activated, function()
        self.Model.UsePointEvent:Action("speed",self:GetUsePoints())
    end);
    self:Upd(self.Model)
end

function M.GetUsePoints(self)
   
    local count=nil

    local s,e=xpcall(function()
        count=  tonumber(self.insts.CostPoints.Text)
   end,debug.traceback)

   count=count or 1

    if not s then
        self.insts.CostPoints.Text=count
    end
    return count
end
function M.Upd(self,data)

    -- self.insts.Hp.num.Text =BigNumberHelper:ToString(data.hp)
    -- self.insts.Damage.num.Text =BigNumberHelper:ToString(data.damge)
    -- self.insts.Speed.num.Text =BigNumberHelper:ToString(data.speed)
    -- self.insts.Luck.num.Text =BigNumberHelper:ToString(data.lucky)
    -- self.insts.HadPoints.Text =BigNumberHelper:ToString(data.points)
    -- self.insts.CostPoints.Text =BigNumberHelper:ToString(data.costPoints) 920 8

    -- self.insts.Hp.num.Text ="x"..math.floor(data.values.hp*100).."%"
    -- self.insts.Damage.num.Text =  "x"..math.floor(data.values.damge*100).."%"
    -- self.insts.Speed.num.Text ="+"..data.values.speed
    -- self.insts.Luck.num.Text ="+"..data.values.lucky

    self.insts.Hp.num.Text ="lv."..data.values.hp
    self.insts.Damage.num.Text ="lv."..data.values.damge
    self.insts.Speed.num.Text ="lv."..data.values.speed
    self.insts.Luck.num.Text ="lv."..data.values.lucky


    self.insts.HadPoints.Text =data.points
  


    for k,v in pairs(data.cost) do
        self.insts.Refund.cost.Text=BigNumberHelper:ToString(v)
        local icon=_G.CommonOHOH.load.ItemTool().GetItemShowView(k)
        self.insts.Refund.icon.Image=icon
    end
end


function M.dtor(self)
	M.super.dtor(self);
end;



return M
